import { createPinia } from 'pinia'
import vuexStore from '@/store'

import _http from './utils/http' // http

import adminStore from './store'
import _useUserStore from './stores/user'

// 组件
import Page from './components/Page.vue'
import PageMain from './components/PageMain.vue'
// import PageEdit from './components/PageEdit.vue'
import DialogEdit from './components/DialogEdit.vue'

const components = [Page, PageMain, DialogEdit]

// mixins
import pageList from './mixins/page-list'
import pageEdit from './mixins/page-edit'
import dialogEdit from './mixins/dialog-edit'

// hooks
import { usePageList } from './hooks/page-list'
import { usePageEdit } from './hooks/page-edit'

export const hooks = {
  usePageList,
  usePageEdit,
}

export const mixins = {
  pageList,
  pageEdit,
  dialogEdit,
}

export const http = _http
export const useUserStore = _useUserStore

export { usePageList } from './hooks/page-list'
export { usePageEdit } from './hooks/page-edit'

export default {
  http: _http,
  install(app) {
    const store = createPinia()

    app.use(store)

    components.forEach(component => {
      app.component(component.name, component)
    })

    // axios
    app.config.globalProperties.$http = _http
    vuexStore.registerModule('app', adminStore)
  },
}
